<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Moodle Docs: How to use CVS</title>
<link rel="stylesheet" href="docstyles.css" type="TEXT/CSS" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
style ol {margin-left:40px;}
.style1 {color: #990000}
.style3 {color: #990000; font-weight: bold; }
.style4 {
	color: #0000CC;
	font-weight: bold;
}
-->
    </style>
</head>
<body>
<h1>CVS for Moodle Developers</h1>
<blockquote>
  <p>CVS is the <strong>Concurrent Versioning System</strong>, a commonly-used way of managing source code for large software projects. CVS keeps all versions of all files so that nothing is ever lost, and usage by different people is tracked. It also provides ways to merge code if two or more people are working on the same file. All code and all versions are stored on a central server (in the case of Moodle, at <a target="_top" href="http://www.sf.net/">Sourceforge</a>). </p>
  <p>If you just want to download Moodle using CVS to run a site, then you probably don't need this page - just follow the simpler CVS instructions on the <a target="_top" href="http://moodle.org/download">Moodle download page</a>.</p>
  <p>&nbsp;</p>
  <ol>
    <li><a href="#n1">Joining the project as a developer</a></li>
    <li><a href="#n2">CVS Modules</a> </li>
    <li><a href="#n3">Basic CVS Commands</a> <br />
      3.1. <a href="#n3.1">CVS on Unix</a> <br />
      3.2. <a href="#n3.2">CVS on Windows</a></li>
    <li> <a href="#n4">Working with Branches</a><br />
      4.1. <a href="#n4.1">Trunk development</a><br />
      4.2. <a href="#n4.2">Stable branches for each release</a><br />
      4.3. <a href="#n4.3">Feature branches for large changes</a> </li>
  </ol>
</blockquote>
<br />
  <h2><a name="n1" id="n1"></a>1. Joining the project as a developer</h2>
  <blockquote>
    <p>So, you've been offered CVS write access to help us develop and maintain Moodle! <a href="http://sourceforge.net/project/memberlist.php?group_id=30935">Welcome aboard</a>!</p>
    <p>To be able to write changes into <a target="_top" href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/moodle/moodle/">Moodle's CVS archive</a>, you first need to have an account at Sourceforge (<a href="http://sourceforge.net/account/register.php">registration is free and easy</a>). For the examples on this page, let's assume your username is <strong><font color="#990000">myusername</font></strong> and your password is <strong><font color="#990000">mypassword</font></strong>. Take special note of the sourceforge instructions to <a target="_top" href="http://sourceforge.net/docman/display_doc.php?docid=768&amp;group_id=1#develhomedir">create your CVS home directory</a> - something you have to do with every new account to "enable" it for CVS. Basically you just have to use ssh to interactively connect to cvs.sourceforge.net.</p>
    <p>Once you have a working Sourceforge account, contact <a 
  target="_top" href="http://moodle.org/user/view.php?id=1&amp;course=1">Martin Dougiamas</a> so he can set up your account with write access to particular Moodle directories.</p>
    <p>To avoid being prompted for <strong><font color="#990000">mypassword</font></strong> every time you run a CVS command, follow the <a target="_top" href="http://sourceforge.net/account/editsshkeys.php">Sourceforge directions for using authorized keys</a>. This step is optional, but it can make your CVS experience a lot nicer.</p>
    <p>With that done, you should have all the permissions you need, so you just need to set up your machine and download the current sources so you can start working on them. </p>
    <p>&nbsp;</p>
  </blockquote>
  <h2><a name="n2" id="n2"></a>2. CVS Modules</h2>
  <blockquote>
    <p>Within CVS, the word &quot;modules&quot; refers to separate collections of code. In Moodle we have the following modules within our repository:</p>
    <blockquote>
      <p><strong>moodle</strong> - the main Moodle source code</p>
      <p><strong>contrib</strong> - user contributions and other assorted code in development</p>
      <p><strong>mysql</strong> - a customised phpMyAdmin to plug into Moodle for database admin</p>
      <p><strong>windows-cron</strong> - a small package that makes cron possible on Windows systems</p>
      <p><strong>docs</strong> - various extra user-contributed documentation</p>
    </blockquote>
    <p>Most people are working on the existing features in the <strong>moodle</strong> module, but many are also contributing new ideas in the <strong>contrib</strong> modules. Once code reaches a certain level of maturity in the <strong>contrib</strong> area, it can be migrated over into the main <strong>moodle</strong> tree. </p>
    <p>&nbsp;</p>
  </blockquote>
  <h2><a name="n3" id="n3"></a>3. Basic CVS Commands </h2>
  <blockquote>
    <h3><a name="n3.1" id="n3.1"></a>3.1 CVS on Unix </h3>
    <blockquote>
      <p>Sourceforge CVS uses ssh as a transport layer for security, so you will have to set a CVS_RSH environment variable in your Unix shell. It's best to put these commands in your .bashrc or .cshrc so you don't have to type it all the time<strong>:</strong></p>
       <div class="commandline">setenv CVS_RSH ssh <em>(for csh, tcsh etc)</em><br /> 
	    export CVS_RSH=ssh <em>(for sh, bash etc)</em></div>  
      <p>Next, you can check out the latest development version of Moodle using this (all one line): </p>
       <div class="commandline">cvs -z3 -d:ext:<span class="style1">myusername</span>@cvs.sourceforge.net:/cvsroot/moodle co moodle</div>      
      <p>The command is similar for other CVS modules:</p>
       <div class="commandline">cvs -z3 -d:ext:myusername@cvs.sourceforge.net:/cvsroot/moodle co contrib</div>      
      <p>Don't try to do run this first CVS command over an existing moodle installation: start fresh with a new directory.</p>
      <p>Note that you will be prompted for <strong><font color="#990000">mypassword</font></strong> for each command unless you set up <a target="_top" href="http://sourceforge.net/account/editsshkeys.php">authorized keys</a>.</p>
      <p>Now, you should have a new 'moodle' directory. You can rename it and move it around if you like. Go into it: </p>
       <div class="commandline">cd moodle </div>      
      <p>All the latest Moodle files should be in there. You can now change files in your copy. To compare your files and directories against the main CVS copy on the server use cvs diff, e.g.: </p>
       <div class="commandline">cvs diff -c config-dist.php<br />
       cvs diff -c lang </div>
      <p>To fetch the latest updates from the server use: </p>
      <div class="commandline">cvs update -dP</div>
      <p>To copy your new files back to the server you would do something like: </p>
      <div class="commandline">cd lang/ca <br />
cvs commit</div>
      <p>You will be prompted to add some comments (depends on your default text editor) ... add a meaningful comment and close the editor ... the files will be sent to Sourceforge and stored. Done! </p>
      <p>To save more time you can put default arguments into a file called .cvsrc in your home directory. For example, mine contains: </p>
      <div class="commandline">diff -c <br />
update -dP</div>
      <p>Try 'cvs help' for more details ... </p>
      <p>&nbsp;</p>
    </blockquote>
    <h3><a name="n3.2" id="n3.2"></a>3.2 CVS on Windows </h3>
    <blockquote>
      <p>First, you need to download a completely fresh copy of Moodle using your developer account.</p>
    </blockquote>
        <ol>
          <li> Get TortoiseCVS from <a target="_top" href="http://www.tortoisecvs.org/">tortoisecvs.org</a> and install it, then reboot.</li>
          <li>Find or create a new folder somewhere where you want Moodle to be downloaded to.</li>
          <li>Right-mouse-click that folder and choose &quot;<strong>CVS Checkout</strong>&quot; from the menu. You should see a dialog box.</li>
          <li>Copy this text into the CVSROOT field (using your own username!):
            <pre> :ext:<font color="#990000">myusername</font>@cvs.sourceforge.net:/cvsroot/moodle</pre>
          </li>
          <li>Under the &quot;Module&quot; field, type &quot;<strong>moodle</strong>&quot; to get the latest development version of Moodle, &quot;<strong>contrib</strong>&quot; to get the contributions directory, or &quot;<strong>mysql</strong>&quot; to get the MySQL Admin module.</li>
          <li>Press the button: &quot;<strong>OK</strong>&quot; and everything should be downloaded.<br />
          </li>
        </ol>
    <blockquote>
      <p>A dialog box should show all the files being downloaded, and after a while you should have a complete copy of Moodle. After this first checkout, you can fetch the latest updated files from the CVS server:</p>
    </blockquote>
        <ol>
          <li> Right-mouse-click on your Moodle folder (or any file) and select &quot;<strong>CVS Update</strong>&quot;. </li>
          <li>Sit back and watch the logs scroll by. Take note of conflicts that may occur if your local code has changes that conflict with the incoming versions - you will need to edit these files and resolve the conflicts manually. <br />
          </li>
        </ol>
    <blockquote>
      <p>After modifying files (you will notice their icons change from green to red!), you can commit them back to the CVS server like this:</p>
    </blockquote>
        <ol>
          <li> Right-mouse-click on your Moodle folder (or any file) and select &quot;<strong>CVS Commit...</strong>&quot;.</li>
          <li>In the dialog box, type a clear description of the changes you are committing.</li>
          <li>Click &quot;OK&quot;. Your changes will be sent to the server.<br />
          </li>
        </ol>
<br />
  </blockquote>
  <h2><a name="n4" id="n4"></a>4. Working with Branches</h2>
  <blockquote>
    <p>This diagram shows how the main <strong>moodle</strong> module branches into different versions over time.</p>
    <p align="center"><img src="pix/cvstree.png" width="500" height="200" /></p>
    <p align="left">To see all the current tags and branches that are available, use this command on any old file (such as index.php in the top moodle directory):</p>
    <div class="commandline">cvs status -v index.php</div>
    <p>Some tagging guidelines:</p>
    <ul>
      <li>Tag and branch names should always be all upper-case.</li>
      <li>Tags and branches should ALWAYS be applied to the <strong>entire module</strong> (all of Moodle). Don't tag individual files or directories. </li>
      <li>We don't allow renaming of tags because people may be relying on them, so get them right the first time! </li>
    </ul>
</blockquote>
<br />
    <h3><a name="n4.1" id="n4.1"></a>4.1 Trunk development</h3>
    <blockquote>
      <p>The Trunk of CVS is the main development version of Moodle. In CVS it is also known as the <span class="style4">HEAD</span>, or default branch.</p>
      <p>Moodle developers try to keep this stable as possible, but as it usually contains new code it probably has bugs and small instabilities.</p>
      <p>Every now and then we decide the product has enough features to make a release. At this time, the trunk is tagged with a <strong>MOODLE_XX_BETA</strong> tag (in case we ever want to roll back to that point) and a new branch is formed for the release, called <span class="style1">MOODLE_XX_STABLE</span>. </p>
      <p>A Beta package is also released at this point - it's for testers who don't use CVS but want to test the latest features and report bugs.</p>
    </blockquote>
    <p>&nbsp;</p>
    <h3><a name="n4.2" id="n4.2"></a>4.2 Stable branches for each release</h3>
    <blockquote>
      <p>As soon as the stable branch <span class="style3">MOODLE_XX_STABLE</span> is created, development efforts will fork into two streams for a while. Some people may continue working on new features in the trunk for the next release, but most developers should be concentrating on using the current <span class="style1"><strong>STABLE</strong></span> branch and fixing bugs that are found in it. </p>
      <p>You can switch your local copy of Moodle to the STABLE version using the following command in Unix from the root directory:</p>
      <div class="commandline">cvs update -dP -r <span class="style1">MOODLE_XX_STABLE</span></div>
      <p>After that, all the commands described above will apply to that stable version. To return to the trunk version just issue:</p>
      <div class="commandline">cvs update -dPA</div>
      <p>On Windows clients you should have a menu from which you can choose the branch. </p>
      <p>Once the new STABLE branch really stabilises, a release can be declared. Packages are created for distribution and the branch will be tagged (by Martin) with a tag named: <strong>MOODLE_XXX</strong></p>
      <p>Periodically, bug fixes in the STABLE branch should be merged into the trunk so that they become available in future versions of Moodle. A floating tag called MOODLE_XX_MERGED will be maintained to keep track of the last merge. The procedure for such a merge is as follows:</p>
        <ol>
          <li>Get out the very latest trunk version.<br />
            <br />
            <div class="commandline">cvs update -dPA</div>
          </li>
          <li>Merge everything on the branch since the last merge, into your trunk version<br /><br />
            <div class="commandline">cvs update -kk -j MOODLE_13_MERGED -j MOODLE_13_STABLE</div>
	      </li>
          <li>Carefully watch the update logs for conflicts, and fix every file that you see with a conflict</li>
          <li>Check the merged copy back into CVS trunk version<br />
            <br />
            <div class="commandline">cvs commit</div>
          </li>
          <li>Go back to the branch version<br /><br />
            <div class="commandline">cvs update -dPr MOODLE_13_STABLE</div>
			</li>
          <li>Update the floating merge tag so that this process can be repeated next time<br /><br />
            <div class="commandline">cvs tag -RF MOODLE_13_MERGED</div>
          </li>
        </ol>
      <p><br />
        Finally, the values for <em>$version</em> in all the Moodle version.php files within the stable branch should not be updated at all if possible (except the last digit if necessary). The reason is that someone updating from a very stable version to the next very stable version could miss database upgrades that happened on the trunk. </p>
    </blockquote>
<br />
    <h3><a name="n4.3" id="n4.3"></a>4.3 Feature branches for large changes </h3>
    <blockquote>
      <p>Occasionally, there may be a very large feature that needs to be checked in so several people can work on it, but it is too unstable to be included in the main development trunk.</p>
      <p>In these cases a short-term branch can be created to work on the feature, and then merged back into the main trunk as soon as possible. An example called <span class="style1"><strong>MOODLE_14_WIDGET</strong></span> branch can be seen in the above diagram.</p>
      <p>If you need to do this for your new WIDGET feature, follow these steps:</p>
        <ol>
          <li>Discuss with other developers to make sure it's necessary!</li>
          <li>Make a new tag on the <strong>trunk</strong> (for all of moodle) called <strong>MOODLE_XX_WIDGET_PRE</strong>
		  <br /><br />
            <div class="commandline">cvs tag -R MOODLE_XX_WIDGET_PRE</div></li>
          <li>Create your branch called <span class="style1"><strong>MOODLE_XX_WIDGET</strong></span>
		  <br /><br />
            <div class="commandline">cvs tag -Rb <span class="style1">MOODLE_XX_WIDGET</span></div></li>
          <li>Work in that branch until the feature is reasonably stable. Commit as necessary.
		  <br /><br />
            <div class="commandline">cvs commit</div></li>
          <li>When ready, merge the whole branch into the trunk, fix conflicts, commit it to the trunk and then abandon the branch.
		  <br />
		  <br />
            <div class="commandline">
            <strong>cvs update -dPA</strong><br />
            <strong>cvs update -kk -j <span class="style1">MOODLE_XX_WIDGET</span></strong><br />
            <strong>cvs commit </strong></div>
          </li>
      </ol>
</blockquote>
<br />
<blockquote>
  <p align="center">Good luck, be careful and have fun!</p>
</blockquote>
<br />
<p align="center"><font size="1"><a href="." target="_top">Moodle Documentation</a></font></p>
<p align="center"><font size="1">Version: $Id$</font></p>
</body>
</html>
